package main

import "fmt"

type Student struct {
	sid    int
	name   string
	age    int8
	course []string //  选秀课程
}

func CourseInit(stu Student) {
	stu.course = []string{"chinese", "math", "english"}
	fmt.Println(stu)
}

func CourseInit2(stu *Student) {
	(*stu).course = []string{"chinese", "math", "english"}
}

func main() {

	// 案例1
	s1 := Student{sid: 1001, name: "alvin", age: 32}
	s2 := s1 // 值拷贝
	fmt.Println(s2)
	s1.age = 100
	fmt.Println(s2.name)

	// 如果希望s3的值跟随s2保持一致怎么实现
	s3 := &s1 // var s4 *Student = &s2
	s1.age = 100
	fmt.Println((*s3).age)
	fmt.Println(s3.age)

	// 案例2
	var s4 = Student{sid: 1001, name: "alvin", age: 32}
	CourseInit(s4)
	fmt.Println("s报的课程：", s4.course)
	// 怎么能初始化成功呢？
	var s5 = &Student{sid: 1001, name: "alvin", age: 32}
	CourseInit2(s5)
	fmt.Println("s报的课程：", (*s5).course) // *s.course的写法是错误的
	fmt.Println("s报的课程：", s5.course)

}
